package com.itheima.dao;

import com.itheima.pojo.BlogSort;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;
import java.util.Map;
@Repository
public interface BlogSortDao extends Mapper<BlogSort> {
    @Select("SELECT s.* from t_blog_sort s,t_blog b where s.uid=b.blog_sort_uid and\n" +
            "b.status=1 group by blog_sort_uid desc")
    List<BlogSort> selectSortByCite();

    @Select("SELECT uid,sort_name,content,create_time,update_time,status,sort,click_count FROM t_blog_sort  WHERE  status = 1 order by click_count DESC")
    List<BlogSort> selectSortByClickCount();

    /**
     * 获取每个分类下文章数目
     * @return
     */
    @Select("SELECT bs.uid blogSortUid,bs.sort_name name,count(bs.uid) value FROM t_blog_sort bs, t_blog b WHERE b.blog_sort_uid = bs.uid GROUP BY b.blog_sort_uid")
    List<Map<String,Object>> getBlogCountByBlogSort();
}
